In [1]:
%matplotlib inline
import numpy as np
import pandas as pd
import json
import random
from urllib.request import urlopen

# Visualization
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px
import plotly.graph_objs as go
import plotly.figure_factory as ff
import calmap
import folium
In [2]:
full_table = pd.read_csv('covid_19_clean_complete.csv', parse_dates=['Date'])
full_table.head()
Out[2]:
Province/State Country/Region Lat Long Date Confirmed Deaths Recovered
0 NaN Thailand 15.0000 101.0000 2020-01-22 2.0 0.0 0.0
1 NaN Japan 36.0000 138.0000 2020-01-22 2.0 0.0 0.0
2 NaN Singapore 1.2833 103.8333 2020-01-22 0.0 0.0 0.0
3 NaN Nepal 28.1667 84.2500 2020-01-22 0.0 0.0 0.0
4 NaN Malaysia 2.5000 112.5000 2020-01-22 0.0 0.0 0.0
Creating new feature "Active_case"

Active_case = Confirmed - Deaths - Recovered

In [3]:
full_table['Active'] = full_table['Confirmed'] - full_table['Deaths'] - full_table['Recovered']
In [4]:
full_table.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 19220 entries, 0 to 19219
Data columns (total 9 columns):
Province/State    8432 non-null object
Country/Region    19220 non-null object
Lat               19220 non-null float64
Long              19220 non-null float64
Date              19220 non-null datetime64[ns]
Confirmed         19219 non-null float64
Deaths            19219 non-null float64
Recovered         19219 non-null float64
Active            19219 non-null float64
dtypes: datetime64[ns](1), float64(6), object(2)
memory usage: 1.3+ MB
In [5]:
full_table.isna().sum()
Out[5]:
Province/State    10788
Country/Region        0
Lat                   0
Long                  0
Date                  0
Confirmed             1
Deaths                1
Recovered             1
Active                1
dtype: int64
In [6]:
full_table['Country/Region'].unique()
Out[6]:
array(['Thailand', 'Japan', 'Singapore', 'Nepal', 'Malaysia', 'Canada',
       'Australia', 'Cambodia', 'Sri Lanka', 'Germany', 'Finland',
       'United Arab Emirates', 'Philippines', 'India', 'Italy', 'Sweden',
       'Spain', 'Belgium', 'Egypt', 'Lebanon', 'Iraq', 'Oman',
       'Afghanistan', 'Bahrain', 'Kuwait', 'Algeria', 'Croatia',
       'Switzerland', 'Austria', 'Israel', 'Pakistan', 'Brazil',
       'Georgia', 'Greece', 'North Macedonia', 'Norway', 'Romania',
       'Estonia', 'San Marino', 'Belarus', 'Iceland', 'Lithuania',
       'Mexico', 'New Zealand', 'Nigeria', 'Ireland', 'Luxembourg',
       'Monaco', 'Qatar', 'Ecuador', 'Azerbaijan', 'Armenia',
       'Dominican Republic', 'Indonesia', 'Portugal', 'Andorra', 'Latvia',
       'Morocco', 'Saudi Arabia', 'Senegal', 'Argentina', 'Chile',
       'Jordan', 'Ukraine', 'Hungary', 'Liechtenstein', 'Poland',
       'Tunisia', 'Bosnia and Herzegovina', 'Slovenia', 'South Africa',
       'Bhutan', 'Cameroon', 'Colombia', 'Costa Rica', 'Peru', 'Serbia',
       'Slovakia', 'Togo', 'Malta', 'Martinique', 'Bulgaria', 'Maldives',
       'Bangladesh', 'Paraguay', 'Albania', 'Cyprus', 'Brunei', 'US',
       'Burkina Faso', 'Holy See', 'Mongolia', 'Panama', 'China', 'Iran',
       'South Korea', 'France', 'Cruise Ship', 'Denmark', 'Czechia',
       'Taiwan', 'Vietnam', 'Russia', 'Moldova', 'Bolivia', 'Honduras',
       'United Kingdom', 'Congo (Kinshasa)', "Cote d'Ivoire", 'Jamaica',
       'Turkey', 'Cuba', 'Guyana', 'Kazakhstan', 'Ethiopia', 'Sudan',
       'Guinea', 'Kenya', 'Antigua and Barbuda', 'Uruguay', 'Ghana',
       'Namibia', 'Seychelles', 'Trinidad and Tobago', 'Venezuela',
       'Eswatini', 'Gabon', 'Guatemala', 'Mauritania', 'Rwanda',
       'Saint Lucia', 'Saint Vincent and the Grenadines', 'Suriname',
       'Kosovo', 'Central African Republic', 'Congo (Brazzaville)',
       'Equatorial Guinea', 'Uzbekistan', 'Netherlands', 'Benin',
       'Liberia', 'Somalia', 'Tanzania', 'Barbados', 'Montenegro',
       'Kyrgyzstan', 'Mauritius', 'Zambia', 'Djibouti', 'Gambia, The',
       'Bahamas, The', 'Chad', 'El Salvador', 'Fiji', 'Nicaragua',
       'Madagascar', 'Haiti', 'Angola', 'Cabo Verde', 'Niger',
       'Papua New Guinea', 'Zimbabwe', 'Cape Verde', 'East Timor',
       'Eritrea', 'Uganda', 'Dominica', 'Grenada', 'Mozambique', 'Syria',
       'Timor-Leste', 'Guadeloupe', 'Reunion', 'French Guiana', 'Mayotte',
       'Greenland', 'Guam', 'Guernsey', 'Jersey', 'Puerto Rico',
       'Republic of the Congo', 'The Bahamas', 'The Gambia'], dtype=object)
In [7]:
full_table['Country/Region'] = full_table['Country/Region'].replace('Mainland China', 'China')
In [8]:
full_table[full_table['Country/Region'] == 'China']
Out[8]:
Province/State Country/Region Lat Long Date Confirmed Deaths Recovered Active
154 Hubei China 30.9756 112.2707 2020-01-22 444.0 17.0 28.0 399.0
158 Guangdong China 23.3417 113.4244 2020-01-22 26.0 0.0 0.0 26.0
159 Henan China 33.8820 113.6140 2020-01-22 5.0 0.0 0.0 5.0
160 Zhejiang China 29.1832 120.0934 2020-01-22 10.0 0.0 0.0 10.0
161 Hunan China 27.6104 111.7088 2020-01-22 4.0 0.0 0.0 4.0
... ... ... ... ... ... ... ... ... ...
19098 Inner Mongolia China 44.0935 113.9448 2020-03-23 75.0 1.0 74.0 0.0
19099 Ningxia China 37.2692 106.1655 2020-03-23 75.0 0.0 75.0 0.0
19103 Qinghai China 35.7452 95.9956 2020-03-23 18.0 0.0 18.0 0.0
19104 Macau China 22.1667 113.5500 2020-03-23 24.0 0.0 10.0 14.0
19112 Tibet China 31.6927 88.0924 2020-03-23 1.0 0.0 1.0 0.0

2046 rows × 9 columns

In [9]:
full_table.head()
Out[9]:
Province/State Country/Region Lat Long Date Confirmed Deaths Recovered Active
0 NaN Thailand 15.0000 101.0000 2020-01-22 2.0 0.0 0.0 2.0
1 NaN Japan 36.0000 138.0000 2020-01-22 2.0 0.0 0.0 2.0
2 NaN Singapore 1.2833 103.8333 2020-01-22 0.0 0.0 0.0 0.0
3 NaN Nepal 28.1667 84.2500 2020-01-22 0.0 0.0 0.0 0.0
4 NaN Malaysia 2.5000 112.5000 2020-01-22 0.0 0.0 0.0 0.0
In [10]:
full_table[['Province/State']] = full_table[['Province/State']].fillna('')
In [11]:
# India, china and the rest
India = full_table[full_table['Country/Region']=='India']
China = full_table[full_table['Country/Region']=='China']
Rest = full_table[full_table['Country/Region']!=('China', 'India')]

Latest Data

In [12]:
temp = full_table.groupby('Date')['Confirmed', 'Deaths', 'Recovered', 'Active'].sum().reset_index()
temp = temp[temp['Date']==max(temp['Date'])].reset_index(drop=True)
temp.style.background_gradient(cmap='Pastel1')
Out[12]:
Date Confirmed Deaths Recovered Active
0 2020-03-23 00:00:00 336004 14643 98334 223027
In [13]:
# color pallette
cnf = '#393e46' # confirmed - grey
dth = '#ff2e63' # death - red
rec = '#21bf73' # recovered - cyan
act = '#fe9801' # active case - yellow
In [14]:
tm = temp.melt(id_vars="Date", value_vars=['Active', 'Deaths', 'Recovered'])
fig = px.treemap(tm, path=["variable"], values="value", height=400, width=600,
                 color_discrete_sequence=[rec, act, dth])
fig.show()

Country Wise Data

In [15]:
full_latest = full_table[full_table['Date'] == max(full_table['Date'])].reset_index()
full_latest_grouped = full_latest.groupby('Country/Region')['Confirmed', 'Deaths', 'Recovered', 'Active'].sum().reset_index()
#full_latest_grouped
In [16]:
temp1 = full_latest_grouped.sort_values(by='Confirmed', ascending=False).reset_index(drop=True)
temp1.style.background_gradient(cmap='Reds')
Out[16]:
Country/Region Confirmed Deaths Recovered Active
0 China 81439 3274 72814 5351
1 Italy 59138 5476 7024 46638
2 US 33276 417 178 32681
3 Spain 28768 1772 2575 24421
4 Germany 24873 94 266 24513
5 Iran 21638 1685 7931 12022
6 France 16044 674 2200 13170
7 South Korea 8897 104 2909 5884
8 Switzerland 7245 98 131 7016
9 United Kingdom 5741 282 67 5392
10 Netherlands 4216 180 2 4034
11 Belgium 3401 75 263 3063
12 Austria 3244 16 9 3219
13 Norway 2383 7 1 2375
14 Sweden 1934 21 16 1897
15 Portugal 1600 14 5 1581
16 Brazil 1593 25 2 1566
17 Denmark 1514 13 1 1500
18 Canada 1470 21 10 1439
19 Australia 1314 7 88 1219
20 Malaysia 1306 10 139 1157
21 Turkey 1236 30 0 1206
22 Czechia 1120 1 6 1113
23 Japan 1086 40 235 811
24 Israel 1071 1 37 1033
25 Ireland 906 4 5 897
26 Luxembourg 798 8 6 784
27 Ecuador 789 14 3 772
28 Pakistan 776 5 5 766
29 Cruise Ship 712 8 325 379
30 Poland 634 7 1 626
31 Chile 632 1 8 623
32 Finland 626 1 10 615
33 Greece 624 15 19 590
34 Thailand 599 1 44 554
35 Iceland 568 1 36 531
36 Indonesia 514 48 29 437
37 Saudi Arabia 511 0 16 495
38 Qatar 494 0 33 461
39 Singapore 455 2 144 309
40 Romania 433 3 64 366
41 Slovenia 414 2 0 412
42 India 396 7 27 362
43 Philippines 380 25 17 338
44 Russia 367 0 16 351
45 Peru 363 5 1 357
46 Bahrain 332 2 149 181
47 Egypt 327 14 56 257
48 Estonia 326 0 2 324
49 South Africa 274 0 0 274
50 Croatia 254 1 5 248
51 Mexico 251 2 4 245
52 Lebanon 248 4 8 236
53 Panama 245 3 0 242
54 Iraq 233 20 57 156
55 Colombia 231 2 3 226
56 Argentina 225 4 3 218
57 Serbia 222 2 1 219
58 Dominican Republic 202 3 0 199
59 Algeria 201 17 65 119
60 Armenia 194 0 2 192
61 Kuwait 188 0 27 161
62 Bulgaria 187 3 3 181
63 Slovakia 185 1 7 177
64 Taiwan 169 2 28 139
65 San Marino 160 20 4 136
66 United Arab Emirates 153 2 38 113
67 Latvia 139 0 1 138
68 Uruguay 135 0 0 135
69 Costa Rica 134 2 2 130
70 Lithuania 131 1 1 129
71 Hungary 131 6 16 109
72 Bosnia and Herzegovina 126 1 2 123
73 Morocco 115 4 3 108
74 North Macedonia 114 1 1 112
75 Vietnam 113 0 17 96
76 Andorra 113 1 1 111
77 Jordan 112 0 1 111
78 Cyprus 95 1 3 91
79 Moldova 94 1 1 92
80 Malta 90 0 2 88
81 Albania 89 2 2 85
82 Brunei 88 0 2 86
83 Cambodia 84 0 1 83
84 Sri Lanka 82 0 3 79
85 Belarus 76 0 15 61
86 Burkina Faso 75 4 5 66
87 Tunisia 75 3 1 71
88 Ukraine 73 3 1 69
89 Venezuela 70 0 15 55
90 Senegal 67 0 5 62
91 New Zealand 66 0 0 66
92 Azerbaijan 65 1 10 54
93 Kazakhstan 60 0 0 60
94 Guadeloupe 56 0 0 56
95 Oman 55 0 17 38
96 Georgia 54 0 3 51
97 Trinidad and Tobago 50 0 1 49
98 Reunion 47 0 0 47
99 Uzbekistan 43 0 0 43
100 Afghanistan 40 1 1 38
101 Cameroon 40 0 0 40
102 Liechtenstein 37 0 0 37
103 Martinique 37 1 0 36
104 Cuba 35 1 0 34
105 Congo (Kinshasa) 30 1 0 29
106 Nigeria 30 0 2 28
107 Bangladesh 27 2 3 22
108 Honduras 26 0 0 26
109 Bolivia 24 0 0 24
110 Ghana 24 1 0 23
111 Monaco 23 0 1 22
112 Paraguay 22 1 0 21
113 Montenegro 21 0 0 21
114 Guatemala 19 1 0 18
115 Rwanda 19 0 0 19
116 Mauritius 18 1 0 17
117 French Guiana 18 0 6 12
118 Togo 16 0 1 15
119 Jamaica 16 1 2 13
120 Kenya 15 0 0 15
121 Kyrgyzstan 14 0 0 14
122 Barbados 14 0 0 14
123 Cote d'Ivoire 14 0 1 13
124 Maldives 13 0 0 13
125 Tanzania 12 0 0 12
126 Mayotte 11 0 0 11
127 Ethiopia 11 0 4 7
128 Mongolia 10 0 0 10
129 Guyana 7 1 0 6
130 Seychelles 7 0 0 7
131 Equatorial Guinea 6 0 0 6
132 Suriname 5 0 0 5
133 Gabon 5 1 0 4
134 Eswatini 4 0 0 4
135 Bahamas, The 4 0 0 4
136 Congo (Brazzaville) 3 0 0 3
137 Zambia 3 0 0 3
138 Madagascar 3 0 0 3
139 Cabo Verde 3 0 0 3
140 Central African Republic 3 0 0 3
141 El Salvador 3 0 0 3
142 Zimbabwe 3 0 0 3
143 Liberia 3 0 0 3
144 Namibia 3 0 0 3
145 Saint Lucia 2 0 0 2
146 Fiji 2 0 0 2
147 Haiti 2 0 0 2
148 Guinea 2 0 0 2
149 Sudan 2 1 0 1
150 Nicaragua 2 0 0 2
151 Nepal 2 0 1 1
152 Niger 2 0 0 2
153 Bhutan 2 0 0 2
154 Benin 2 0 0 2
155 Kosovo 2 0 0 2
156 Mauritania 2 0 0 2
157 Angola 2 0 0 2
158 Mozambique 1 0 0 1
159 Timor-Leste 1 0 0 1
160 Antigua and Barbuda 1 0 0 1
161 Uganda 1 0 0 1
162 Saint Vincent and the Grenadines 1 0 0 1
163 Chad 1 0 0 1
164 Djibouti 1 0 0 1
165 Gambia, The 1 0 0 1
166 Eritrea 1 0 0 1
167 Grenada 1 0 0 1
168 Syria 1 0 0 1
169 Dominica 1 0 0 1
170 Somalia 1 0 0 1
171 Papua New Guinea 1 0 0 1
172 Holy See 1 0 0 1
173 Guam 0 1 0 -1
174 Cape Verde 0 0 0 0
175 East Timor 0 0 0 0
176 Guernsey 0 0 0 0
177 Jersey 0 0 0 0
178 Greenland 0 0 0 0
179 Puerto Rico 0 1 0 -1
180 The Gambia 0 0 0 0
181 Republic of the Congo 0 0 0 0
182 The Bahamas 0 0 0 0

Maps

In [17]:
fig = px.choropleth(full_latest_grouped, locations=full_latest_grouped['Country/Region'],
                    color=full_latest_grouped['Confirmed'],locationmode='country names', 
                    hover_name=full_latest_grouped['Country/Region'], 
                    color_continuous_scale=px.colors.sequential.deep)
fig.update_layout(
    title='Confirmed Cases In The World',
)
fig.show()
In [18]:
formated_gdf = full_table.groupby(['Date', 'Country/Region'])['Confirmed', 'Deaths', 'Recovered'].max()
formated_gdf = formated_gdf.reset_index()
formated_gdf['Date'] = pd.to_datetime(formated_gdf['Date'])
formated_gdf['Date'] = formated_gdf['Date'].dt.strftime('%m/%d/%Y')
formated_gdf['size'] = formated_gdf['Confirmed'].pow(0.3)

fig = px.scatter_geo(formated_gdf, locations="Country/Region", locationmode='country names', 
                     color="Confirmed", size='size', hover_name="Country/Region", 
                     range_color= [0, max(formated_gdf['Confirmed'])+2], 
                     projection="natural earth", animation_frame="Date", 
                     title='Spread over time')
fig.update(layout_coloraxis_showscale=False)
fig.show()

Countries With Death Reports

In [19]:
temp_flg = temp1[temp1['Deaths']>0][['Country/Region', 'Deaths']]
temp_flg.sort_values('Deaths', ascending=False).reset_index(drop=True).style.background_gradient(cmap='Reds')
Out[19]:
Country/Region Deaths
0 Italy 5476
1 China 3274
2 Spain 1772
3 Iran 1685
4 France 674
5 US 417
6 United Kingdom 282
7 Netherlands 180
8 South Korea 104
9 Switzerland 98
10 Germany 94
11 Belgium 75
12 Indonesia 48
13 Japan 40
14 Turkey 30
15 Brazil 25
16 Philippines 25
17 Sweden 21
18 Canada 21
19 San Marino 20
20 Iraq 20
21 Algeria 17
22 Austria 16
23 Greece 15
24 Ecuador 14
25 Egypt 14
26 Portugal 14
27 Denmark 13
28 Malaysia 10
29 Luxembourg 8
30 Cruise Ship 8
31 India 7
32 Norway 7
33 Australia 7
34 Poland 7
35 Hungary 6
36 Pakistan 5
37 Peru 5
38 Burkina Faso 4
39 Argentina 4
40 Morocco 4
41 Ireland 4
42 Lebanon 4
43 Tunisia 3
44 Romania 3
45 Dominican Republic 3
46 Bulgaria 3
47 Ukraine 3
48 Panama 3
49 Albania 2
50 United Arab Emirates 2
51 Bangladesh 2
52 Costa Rica 2
53 Taiwan 2
54 Serbia 2
55 Mexico 2
56 Colombia 2
57 Bahrain 2
58 Slovenia 2
59 Singapore 2
60 Guatemala 1
61 Cuba 1
62 Congo (Kinshasa) 1
63 Chile 1
64 Ghana 1
65 Paraguay 1
66 Jamaica 1
67 Mauritius 1
68 Afghanistan 1
69 Guyana 1
70 Gabon 1
71 Sudan 1
72 Guam 1
73 Martinique 1
74 Israel 1
75 Azerbaijan 1
76 Finland 1
77 Thailand 1
78 Iceland 1
79 Moldova 1
80 Cyprus 1
81 Andorra 1
82 North Macedonia 1
83 Czechia 1
84 Bosnia and Herzegovina 1
85 Lithuania 1
86 Croatia 1
87 Slovakia 1
88 Puerto Rico 1

Countries with no cases recovered

In [20]:
temp = temp1[temp1['Recovered']==0][['Country/Region', 'Confirmed', 'Deaths', 'Recovered']]
temp.reset_index(drop=True).style.background_gradient(cmap='Reds')
Out[20]:
Country/Region Confirmed Deaths Recovered
0 Turkey 1236 30 0
1 Slovenia 414 2 0
2 South Africa 274 0 0
3 Panama 245 3 0
4 Dominican Republic 202 3 0
5 Uruguay 135 0 0
6 New Zealand 66 0 0
7 Kazakhstan 60 0 0
8 Guadeloupe 56 0 0
9 Reunion 47 0 0
10 Uzbekistan 43 0 0
11 Cameroon 40 0 0
12 Liechtenstein 37 0 0
13 Martinique 37 1 0
14 Cuba 35 1 0
15 Congo (Kinshasa) 30 1 0
16 Honduras 26 0 0
17 Bolivia 24 0 0
18 Ghana 24 1 0
19 Paraguay 22 1 0
20 Montenegro 21 0 0
21 Guatemala 19 1 0
22 Rwanda 19 0 0
23 Mauritius 18 1 0
24 Kenya 15 0 0
25 Kyrgyzstan 14 0 0
26 Barbados 14 0 0
27 Maldives 13 0 0
28 Tanzania 12 0 0
29 Mayotte 11 0 0
30 Mongolia 10 0 0
31 Guyana 7 1 0
32 Seychelles 7 0 0
33 Equatorial Guinea 6 0 0
34 Suriname 5 0 0
35 Gabon 5 1 0
36 Eswatini 4 0 0
37 Bahamas, The 4 0 0
38 Congo (Brazzaville) 3 0 0
39 Zambia 3 0 0
40 Madagascar 3 0 0
41 Cabo Verde 3 0 0
42 Central African Republic 3 0 0
43 El Salvador 3 0 0
44 Zimbabwe 3 0 0
45 Liberia 3 0 0
46 Namibia 3 0 0
47 Saint Lucia 2 0 0
48 Fiji 2 0 0
49 Haiti 2 0 0
50 Guinea 2 0 0
51 Sudan 2 1 0
52 Nicaragua 2 0 0
53 Niger 2 0 0
54 Bhutan 2 0 0
55 Benin 2 0 0
56 Kosovo 2 0 0
57 Mauritania 2 0 0
58 Angola 2 0 0
59 Mozambique 1 0 0
60 Timor-Leste 1 0 0
61 Antigua and Barbuda 1 0 0
62 Uganda 1 0 0
63 Saint Vincent and the Grenadines 1 0 0
64 Chad 1 0 0
65 Djibouti 1 0 0
66 Gambia, The 1 0 0
67 Eritrea 1 0 0
68 Grenada 1 0 0
69 Syria 1 0 0
70 Dominica 1 0 0
71 Somalia 1 0 0
72 Papua New Guinea 1 0 0
73 Holy See 1 0 0
74 Guam 0 1 0
75 Cape Verde 0 0 0
76 East Timor 0 0 0
77 Guernsey 0 0 0
78 Jersey 0 0 0
79 Greenland 0 0 0
80 Puerto Rico 0 1 0
81 The Gambia 0 0 0
82 Republic of the Congo 0 0 0
83 The Bahamas 0 0 0

Top 10 Countries

In [21]:
fig = go.Figure(data=[go.Bar(
            x=temp1['Country/Region'][0:10], y=temp1['Confirmed'][0:10],
            text=temp1['Confirmed'][0:10],
            textposition='auto',
            marker_color='yellow',

        )])
fig.update_layout(
    title='Top 10 infected Cases',
    xaxis_title="Countries",
    yaxis_title="Confirmed Cases",
)
fig.show()
In [22]:
temp2 = full_latest_grouped.sort_values(by='Deaths', ascending=False).reset_index(drop=True)
fig = go.Figure(data=[go.Bar(
            x=temp2['Country/Region'][0:10], y=temp2['Deaths'][0:10],
            text=temp2['Deaths'][0:10],
            textposition='auto',
            marker_color='red',

        )])
fig.update_layout(
    title='Top 10 Death Cases',
    xaxis_title="Countries",
    yaxis_title="Deaths",
)
fig.show()

Recovered Cases

In [23]:
Recovered_per_country = full_latest.groupby(["Country/Region"])["Recovered"].sum().reset_index().sort_values("Recovered",ascending=False).reset_index(drop=True)
fig = px.pie(Recovered_per_country, values=Recovered_per_country['Recovered'], names=Recovered_per_country['Country/Region'],
             title='Recovered cases',
            )
fig.update_traces(textposition='inside', textinfo='percent+label')
fig.show()
In [24]:
fig = go.Figure(data=[go.Bar(
            x=Recovered_per_country['Country/Region'][0:10], y=Recovered_per_country['Recovered'][0:10],
            text=Recovered_per_country['Recovered'][0:10],
            textposition='auto',
            marker_color='green',

        )])
fig.update_layout(
    title='Top 10 Recovered Countries',
    xaxis_title="Countries",
    yaxis_title="Recovered Cases",
)
fig.show()

China province wise data

In [25]:
china_latest = full_latest[full_latest['Country/Region']=='China']
china_latest_grouped = china_latest.groupby('Province/State')['Confirmed', 'Deaths', 'Recovered', 'Active'].sum().reset_index()
In [26]:
temp2 = china_latest_grouped[['Province/State', 'Confirmed', 'Deaths', 'Recovered']]
temp2 = temp2.sort_values(by='Confirmed', ascending=False)
temp2 = temp2.reset_index(drop=True)
temp2.style.background_gradient(cmap='Pastel1_r')
Out[26]:
Province/State Confirmed Deaths Recovered
0 Hubei 67800 3153 59879
1 Guangdong 1413 8 1332
2 Henan 1274 22 1250
3 Zhejiang 1238 1 1221
4 Hunan 1018 4 1014
5 Anhui 990 6 984
6 Jiangxi 936 1 934
7 Shandong 767 7 751
8 Jiangsu 633 0 631
9 Chongqing 577 6 570
10 Sichuan 543 3 536
11 Beijing 522 8 400
12 Heilongjiang 484 13 465
13 Shanghai 404 4 329
14 Hebei 319 6 310
15 Hong Kong 317 4 100
16 Fujian 313 1 295
17 Guangxi 254 2 250
18 Shaanxi 248 3 239
19 Yunnan 176 2 172
20 Hainan 168 6 161
21 Guizhou 146 2 144
22 Tianjin 141 3 133
23 Gansu 136 2 114
24 Shanxi 133 0 133
25 Liaoning 127 2 124
26 Jilin 93 1 92
27 Xinjiang 76 3 73
28 Ningxia 75 0 75
29 Inner Mongolia 75 1 74
30 Macau 24 0 10
31 Qinghai 18 0 18
32 Tibet 1 0 1

Provinces with no cases recovered

In [27]:
temp = china_latest_grouped[china_latest_grouped['Recovered']==0]
temp = temp[['Province/State', 'Confirmed', 'Deaths', 'Recovered']]
temp = temp.sort_values('Confirmed', ascending=False)
temp = temp.reset_index(drop=True)
temp.style.background_gradient(cmap='Pastel1_r')
Out[27]:
Province/State Confirmed Deaths Recovered

Provinces with all the cases recovered

In [28]:
temp = china_latest_grouped[china_latest_grouped['Confirmed']==
                          china_latest_grouped['Recovered']]
temp = temp[['Province/State', 'Confirmed','Deaths', 'Recovered']]
temp = temp.sort_values('Confirmed', ascending=False)
temp = temp.reset_index(drop=True)
temp.style.background_gradient(cmap='Greens')
Out[28]:
Province/State Confirmed Deaths Recovered
0 Shanxi 133 0 133
1 Ningxia 75 0 75
2 Qinghai 18 0 18
3 Tibet 1 0 1

Provinces with no affected cases anymore

In [29]:
temp = china_latest_grouped[china_latest_grouped['Confirmed']==
                          china_latest_grouped['Deaths']+
                          china_latest_grouped['Recovered']]
temp = temp[['Province/State', 'Confirmed', 'Deaths', 'Recovered']]
temp = temp.sort_values('Confirmed', ascending=False)
temp = temp.reset_index(drop=True)
temp.style.background_gradient(cmap='Greens')
Out[29]:
Province/State Confirmed Deaths Recovered
0 Hunan 1018 4 1014
1 Anhui 990 6 984
2 Guizhou 146 2 144
3 Shanxi 133 0 133
4 Jilin 93 1 92
5 Xinjiang 76 3 73
6 Inner Mongolia 75 1 74
7 Ningxia 75 0 75
8 Qinghai 18 0 18
9 Tibet 1 0 1
In [30]:
gdf = full_table.groupby(['Date', 'Country/Region'])['Confirmed', 'Deaths', 'Recovered'].max()
gdf = gdf.reset_index()

temp = gdf[gdf['Country/Region']=='China'].reset_index()
temp = temp.melt(id_vars='Date', value_vars=['Confirmed', 'Deaths', 'Recovered'],
                var_name='Case', value_name='Count')
fig = px.bar(temp, x="Date", y="Count", color='Case', facet_col="Case",
            title='China', color_discrete_sequence=[cnf, dth, rec])
fig.show()

temp = gdf[gdf['Country/Region']!='China'].groupby('Date').sum().reset_index()
temp = temp.melt(id_vars='Date', value_vars=['Confirmed', 'Deaths', 'Recovered'],
                var_name='Case', value_name='Count')
fig = px.bar(temp, x="Date", y="Count", color='Case', facet_col="Case",
             title='Rest', color_discrete_sequence=[cnf, dth, rec])
fig.show()

Hubei - China - World

In [31]:
def location(row):
    if row['Country/Region']=='China':
        if row['Province/State']=='Hubei':
            return 'Hubei'
        else:
            return 'Other Chinese Provinces'
    else:
        return 'Rest of the World'

temp = full_table.copy()
temp['Region'] = temp.apply(location, axis=1)
temp['Date'] = temp['Date'].dt.strftime('%Y-%m-%d')
temp = temp.groupby(['Region', 'Date'])['Confirmed', 'Deaths', 'Recovered'].sum().reset_index()
temp = temp.melt(id_vars=['Region', 'Date'], value_vars=['Confirmed', 'Deaths', 'Recovered'], 
                 var_name='Case', value_name='Count').sort_values('Count')
# temp = temp.sort_values(['Date', 'Region', 'Case']).reset_index()
temp.head()

fig = px.bar(temp, y='Region', x='Count', color='Case', barmode='group', orientation='h',
             text='Count', title='Hubei - China - World', animation_frame='Date',
             color_discrete_sequence= [dth, rec, cnf], range_x=[0, 70000])
fig.update_traces(textposition='outside')
# fig.update_layout(uniformtext_minsize=8, uniformtext_mode='hide')
# fig.update_layout(yaxis={'categoryorder':'array', 
#                          'categoryarray':['Hubei','Other Chinese Provinces','Rest of the World']})
fig.show()

temp = full_latest.copy()
temp['Region'] = temp.apply(location, axis=1)
temp = temp.groupby('Region')['Confirmed', 'Deaths', 'Recovered'].sum().reset_index()
temp = temp.melt(id_vars='Region', value_vars=['Confirmed', 'Deaths', 'Recovered'], 
                 var_name='Case', value_name='Count').sort_values('Count')
temp.head()

fig = px.bar(temp, y='Region', x='Count', color='Case', barmode='group', orientation='h',
             text='Count', title='Hubei - China - World', 
             color_discrete_sequence= [dth, rec, cnf])
fig.update_traces(textposition='outside')
fig.update_layout(uniformtext_minsize=8, uniformtext_mode='hide')
fig.show()

Country Wise

In [32]:
# converter
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()   

# hide warnings
import warnings
warnings.filterwarnings('ignore')

temp = full_table.groupby(['Date', 'Country/Region'])['Confirmed'].sum()
temp = temp.reset_index().sort_values(by=['Date', 'Country/Region'])
# temp = temp[temp['Confirmed']>100]

plt.style.use('seaborn')
g = sns.FacetGrid(temp, col="Country/Region", hue="Country/Region", 
                  sharey=False, col_wrap=5)
g = g.map(plt.plot, "Date", "Confirmed")
g.set_xticklabels(rotation=90)
plt.show()
In [33]:
temp = full_table.groupby(['Date', 'Country/Region'])['Confirmed'].sum().reset_index().sort_values('Confirmed', ascending=False)

fig = px.line(temp, x="Date", y="Confirmed", color='Country/Region', title='Cases Spread', height=600)
fig.update_layout(xaxis_rangeslider_visible=True)
fig.show()
In [34]:
temp = full_table.groupby(['Date', 'Country/Region'])['Deaths'].sum().reset_index().sort_values('Deaths', ascending=False)

fig = px.line(temp, x="Date", y="Deaths", color='Country/Region', title='Deaths', height=600)
fig.update_layout(xaxis_rangeslider_visible=True)
fig.show()
In [35]:
fig = px.scatter(full_latest_grouped.sort_values('Deaths', ascending=False).iloc[:15, :], 
                 x='Confirmed', y='Deaths', color='Country/Region', size='Confirmed', height=600,
                 text='Country/Region', log_x=True, log_y=True, title='Deaths vs Confirmed')
fig.update_traces(textposition='top center')
fig.update_layout(xaxis_rangeslider_visible=True)
fig.show()
In [36]:
temp = full_table.groupby('Date').sum().reset_index()

temp = temp.melt(id_vars='Date', value_vars=['Active', 'Recovered'], 
                 var_name='Case', value_name='Value')

fig = px.line(temp, x="Date", y="Value", color='Case',  
              title='Active & Recovered cases', color_discrete_sequence=[dth, rec])
fig.update_layout(xaxis_rangeslider_visible=True)
fig.show()
In [ ]: